function [out,utilizzazione] = calcola_distribuzione_stazionaria(lambda,mu,M,B)

out = zeros(1,B+1);

ro = lambda/(M*mu);
a = ro*M;
%calcola pi0

for k = [0:(M)]
    out(1) = out(1) + ((a)^k)/factorial(k);    
end

out(1) = out(1) + ((a)^M/factorial(M))*sum(ro.^[1:(B-M)]);

out(1) = 1/out(1);



for k = 1:B
    if(k <= M)
        out(k+1) = out(1) * ((a)^k) / factorial(k);
    else
        out(k+1) = out(1) * ( (a)^M / factorial(M) ) * (ro^(k-M));
    end

end

if (abs(sum(out)-1)>1e-6)
    fprintf "Errore\n";
end

la = lambda*(1-out(end));
utilizzazione = la/(M*mu);
sum(out);



